//
//  CZDetailFootView.swift
//  GZWeibo007
//
//  Created by 咏兴 on 15/12/25.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

protocol CZDetailFootViewDelegate:NSObjectProtocol{
    func commentsButtonDidClick()
    func repostsButtonDidClick()
    func attitudesButtonDidClick()
}

class CZDetailFootView: UIView {

    weak var btnDelegate:CZDetailFootViewDelegate?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        prepareUI()
        self.backgroundColor = UIColor(white: 237 / 255.0, alpha: 1)

    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func prepareUI(){
        
        //添加按钮
        addSubview(commentButton)
        addSubview(repostButton)
        addSubview(attitudesButton)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let width = UIScreen.mainScreen().bounds.width / 3
        let height:CGFloat = 44
        
        let detailFootViewY = UIScreen.mainScreen().bounds.height - height
        
        self.frame = CGRectMake(0, detailFootViewY, UIScreen.mainScreen().bounds.width, height)
        
        let frame = CGRectMake(0, 0, width, height)

        var index:CGFloat = 0
        //遍历所有子控件,自动布局
        for button in self.subviews{
            
            button.frame = CGRectOffset(frame, index * width, 0)
            
            index++
        }
       
    }
    
    func commentButtonDidClick(){
        btnDelegate?.commentsButtonDidClick()
        print("评论按钮被点击了")
    }
    
    func repostButtonDidClick(){
        btnDelegate?.repostsButtonDidClick()
        print("转发按钮被点击了")
    }
    
    func attitudeButtonDidClick(){
        btnDelegate?.attitudesButtonDidClick()
        print("点赞按钮被点击了")
    }
    
    //MARK: -懒加载
    /// 评论
    private lazy var commentButton:UIButton = {
        let button = UIButton(imageName: "timeline_icon_comment", fontSize: 0, title: "")
        button.addTarget(self, action: "commentButtonDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    
    /// 转发
    private lazy var repostButton:UIButton = {
        let button = UIButton(imageName: "timeline_icon_retweet", fontSize: 0, title: "")
        button.addTarget(self, action: "repostButtonDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()
    
    /// 点赞
    private lazy var attitudesButton:UIButton = {
        let button = UIButton(imageName: "timeline_icon_unlike", fontSize: 0, title: "")
        button.addTarget(self, action: "attitudeButtonDidClick", forControlEvents: UIControlEvents.TouchUpInside)
        return button
    }()


}
